using System;
using System.Diagnostics;

namespace Granite.Wcf.Debugging
{
	/// <summary>
	/// This is a helper class for the debugging attributes
	/// </summary>
	public abstract class DebugAttribute : Attribute
	{
		/// <summary>
		/// Where to send the debugging information
		/// </summary>
		/// <remarks>Defaults to the Debug window</remarks>
		public Granite.Wcf.Debugging.OutputTargets OutputTargets { get; set; }

		/// <summary>
		/// Creates a new instance with OutputTargets = Debug
		/// </summary>
		protected DebugAttribute()
		{
			OutputTargets = Granite.Wcf.Debugging.OutputTargets.Debug;
		}

		/// <summary>
		/// Writes to the indicated output targers
		/// </summary>
		/// <param name="message"></param>
		/// <param name="arguments"></param>
		protected void WriteLine(string message, params string[] arguments)
		{
			if (OutputTargets.HasFlag(Granite.Wcf.Debugging.OutputTargets.Debug))
				Debug.WriteLine(message, arguments);
			if (OutputTargets.HasFlag(Granite.Wcf.Debugging.OutputTargets.Trace))
				Trace.WriteLine(string.Format(message, arguments));
			if (OutputTargets.HasFlag(Granite.Wcf.Debugging.OutputTargets.Console))
				Console.WriteLine(message, arguments);
		}
	}
}
